﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.Designer.Views
{
    public partial class EventProxy
    {
        /// <summary>
        /// 收到创建方案的事件
        /// </summary>
        /// <param name="event"></param>
        [Common.Subscribe]
        public void OnReceiveNCLCreateSolutionEvent(Event.NCL.NCLCreateSolutionEvent @event)
        {
            if (@event.State == Event.NCL.NCLEventState.Sending)
            {
                return;
            }

            if (IsOfflineMode)
            {
                @event.State = Event.NCL.NCLEventState.Finished;
                Event.NCL.NCLEventBus.Publish(@event);

                // 转发出一个ui事件

            }
        }

        /// <summary>
        /// 创建数据源
        /// </summary>
        /// <param name="event"></param>
        [Common.Subscribe]
        public void OnReceiveNCLCreateDataSourceEvent(Event.NCL.NCLCreateDataSourceEvent @event)
        {
            if (@event.State == Event.NCL.NCLEventState.Sending)
            {
                return;
            }

            //if (IsOfflineMode)
            //{
            //    @event.State = Event.NCL.NCLEventState.Finished;
            //    Event.NCL.NCLEventBus.Publish(@event);

            //    UIContext.Current.CurrentSolution.AddDataSource(@event.DataSource);
            //    // 转发出一个ui事件
            //    Event.UI.UIDataSourceCreatedEvent @uiEvent = new Event.UI.UIDataSourceCreatedEvent(@event.DataSource);
            //    Event.UI.UIEventBus.Publish(@uiEvent);
            //}
        }

        /// <summary>
        /// 创建数据集
        /// </summary>
        /// <param name="event"></param>
        [Common.Subscribe]
        public void OnReceiveNCLCreateDataSetEvent(Event.NCL.NCLCreateDataSetEvent @event)
        {
            //if (@event.State == Event.NCL.NCLEventState.Sending)
            //{
            //    return;
            //}

            //if (IsOfflineMode)
            //{
            //    @event.State = Event.NCL.NCLEventState.Finished;
            //    Event.NCL.NCLEventBus.Publish(@event);

            //    // 转发出一个ui事件
            //    for (int index = 0; index < UIContext.Current.CurrentSolution.DataSources.Count; index++)
            //    {
            //        if (UIContext.Current.CurrentSolution.DataSources[index].Id == @event.DataSourceId)
            //        {
            //            UIContext.Current.CurrentSolution.DataSources[index].AddDataSet(@event.DataSet);
            //        }
            //    }
            //    // 转发出一个ui事件
            //    Event.UI.UIDataSetCreatedEvent @uiEvent = new Event.UI.UIDataSetCreatedEvent(@event.DataSourceId, @event.DataSet);
            //    Event.UI.UIEventBus.Publish(@uiEvent);
            //}
        }
    }
}
